﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace GifFrameExtract
{
    class Program
    {
        static void Main(string[] args)
        {

            string source = args[0];


            Image gif = Image.FromFile(source);
            FrameDimension frameDimension = new FrameDimension(gif.FrameDimensionsList[0]);
            int numFrames = gif.GetFrameCount(frameDimension);

            for (int frame = 0; frame < numFrames; frame++)
            {

                using (Bitmap frameImage = new Bitmap(gif))
                using (Graphics frameGfx = Graphics.FromImage(frameImage))
                {

                    gif.SelectActiveFrame(frameDimension, frame);
                    frameGfx.DrawImageUnscaled(gif, 0, 0);

                    string imageName = Path.GetFileNameWithoutExtension(source) + "_" + frame + ".png";
                    frameImage.Save(imageName, ImageFormat.Png);

                }

            }

        }
    }
}
